package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/4/11 15:51
 * 图库  listview 自定义
 */
public class GalleryListAdapter extends BaseAdapter {
    private Context context;
    private List<List<String>> galleryListItem;

    public GalleryListAdapter(Context context, List<List<String>> galleryListItem) {
        this.context = context;
        this.galleryListItem = galleryListItem;
    }

    @Override
    public int getCount() {
        return galleryListItem == null ? 0 : galleryListItem.size();
    }

    @Override
    public Object getItem(int position) {
        return galleryListItem == null ? null : galleryListItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        ViewHolder viewHolder;
        if (rowView == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.gallery_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.tv_gallery = rowView.findViewById(R.id.tv_gallery);
            rowView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) rowView.getTag();
        }
        List<String> galleryShowItem = galleryListItem.get(position);
        if (galleryShowItem != null && galleryShowItem.size() >= 1) {
            viewHolder.tv_gallery.setText(galleryShowItem.get(0));
        }
        return rowView;
    }
    private static class ViewHolder {
        TextView tv_gallery;

    }
}
